// A RESTful factory for retreiving mails from 'mails.json'
app.factory('tasks', ['$http', '$q', function ($http, $q) {
    var rootPath = window.location.origin+'/simuladores';
    var cachegentity;

    return {
        getEntity:function(){return cachegentity;},
        setEntity:function(entity){cachegentity = entity;},
        getList: function () { 
            var path = rootPath + '/taxindexs' ;
            var qdefer = $q.defer();
            $http({
                method: 'GET',
                url: path, 
                async: false,
            }).success(function (data, status, headers, config) {
                qdefer.resolve(data);
            }).error(function (data, status, headers, config) {
                // called asynchronously if an error occurs
                // or server returns response with an error status.
                console.log(data);
            });
            return qdefer.promise;
        },
        insert: function (entity) {
            var path = rootPath + '/taxindexs/insert/'+entity.nm_tax + '/'+entity.ds_tax+'/'+entity.vl_tax_amount;
            var qdefer = $q.defer();
            $http({
                method: 'GET',
                url: path, 
                async: false,
            }).success(function (data, status, headers, config) {
                qdefer.resolve(data);
            }).error(function (data, status, headers, config) {
                // called asynchronously if an error occurs
                // or server returns response with an error status.
                console.log(data);
            });;;
            return qdefer.promise;
        },
        edit:function(entity)
        {
        	 var path = rootPath + '/taxindexs/update/' + entity.id + '/' +entity.nm_tax + '/'+entity.ds_tax+'/'+entity.vl_tax_amount;
             
            var qdefer = $q.defer();
            $http({
                method: 'GET',
                url: path,
                 
                async: false,
            }).success(function (data, status, headers, config) {
                qdefer.resolve(data);
            }).error(function (data, status, headers, config) {
                // called asynchronously if an error occurs
                // or server returns response with an error status.
                console.log(data);
            });
            return qdefer.promise;
        },
        del: function (entity)
        {
            var path = rootPath + '/taxindexs/delete/' + entity.id;
            var qdefer = $q.defer();
            $http({
                method: 'GET',
                url: path,
               
                async: false,
            }).success(function (data, status, headers, config) {
                qdefer.resolve(data);
            }).error(function (data, status, headers, config) {
                // called asynchronously if an error occurs
                // or server returns response with an error status.
                console.log(data);
            });;
            return qdefer.promise;
        }

    }
     
}]);